package com.yjy.service.impl;

import com.yjy.entity.OrderInfo;
import com.yjy.repository.OrderInfoRepository;
import com.yjy.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoRepository orderInfoRepository;

    private Random random_userId = new Random();

    @Override
    public void save() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderName("测试");
        orderInfo.setOrderStatus(1);
        long nextLong = Math.abs(random_userId.nextLong());
        System.out.println(nextLong);
        orderInfo.setUserId(nextLong);
        orderInfoRepository.save(orderInfo);
    }

    /**
     * 查询全部订单信息
     *
     * @return 全部订单信息
     */
    @Override
    public List<OrderInfo> getAll() {
        return orderInfoRepository.findAll();
    }

    /**
     * 分页
     * @param request
     * @return
     */
    @Override
    public Page page(Pageable request) {
        return orderInfoRepository.findAll(request);
    }
}
